#include <sys/types.h>         
#include <sys/socket.h>

#include <sys/un.h>
#include <errno.h>
#include <unistd.h>

#include "ipc_api.h"


typedef struct {
void 		*pTimerHandle ;
int			running;
}timerServer_s;

timerServer_s	timerServer = {NULL,1};
static void timerHandleFunc1(void *ctx)
{
	char * voice = (char * )ctx;
	ipcLogDebug(voice);
}

static void timerHandleFunc2(void *ctx)
{
	char * voice = (char * )ctx;
	ipcLogDebug(voice);
}

int main(int argc,char *argv[])
{
	ipcRet_e	ret = ipcSuccess;
	ipcLog_s	log = {IPC_LOG_DEBUG,IPC_LOG_2_STDERR};
	ipcTimer_s	timer;

	timerServer.running = 50;

	ipcLogInit(&log);
	
	ret = ipcTimerInit(&timerServer.pTimerHandle);
	ipcLogCheckRetThenReturn(ret);

	PUT_ZERO_2_MEMORY(&timer,sizeof(timer));
	timer.executeNumber = IPC_TIMER_EXEXUTE_FOREVER;
	timer.func = timerHandleFunc2;
	timer.funcCtx = "func2";
	timer.period = 5000;
	ipcTimerAdd(timerServer.pTimerHandle,timer);


	timer.executeNumber = 3;
	timer.func = timerHandleFunc1;
	timer.funcCtx = "func1";
	timer.period = 2000;
	ipcTimerAdd(timerServer.pTimerHandle,timer);

	while(timerServer.running)
	{
		ipcTimerExecute(timerServer.pTimerHandle);
		timerServer.running--;

		if(30 == timerServer.running)
		{
			//timer.executeNumber = IPC_TIMER_EXEXUTE_FOREVER;
			timer.func = timerHandleFunc2;
			//timer.funcCtx = "func2";
			//timer.period = 5000;
			ipcTimerDelete(timerServer.pTimerHandle,timer);
		}
		sleep(1);
	}

	ipcTimerDeinit(&timerServer.pTimerHandle);

	return 0;
}

